package ch13;


// Keypad.java
// Represents the keypad of the ATM
import java.util.InputMismatchException;
import java.util.Scanner; // program uses Scanner to obtain user input
import java.util.Random;

public class Keypad {
	private Scanner input; // reads data from the command line
	Random rn = new Random();

	// no-argument constructor initializes the Scanner
	public Keypad() {

		input = new Scanner(System.in);

	} // end no-argument Keypad constructor

	// return an integer value entered by user
	public int getInput() {
		int r_int = -1;
		while(r_int == -1)
		{
			try{
				r_int = input.nextInt();
				break;
			} catch (InputMismatchException e){
				input.next();
				System.out.println("Your input is not a number. Please try again:");
			} 
		} // end method getInput
		return r_int;
	}
	public String getInputS() {
		return input.next(); // we assume that user enters an String
	}
	
	// return an long value entered by user
	public long getInputL() {
		
		long r_long = -1;
		while(r_long == -1)
		{
			try{
				r_long = input.nextLong();
				break;
			} catch (InputMismatchException e){
				input.next();
				System.out.println("Your input is not a number. Please try again:");
			} 
		} // end method getInput
		return r_long;
	}

} // end class Keypad